package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.jicai.R;
import com.sgb.jicai.entity.JcMySupervisionEntity;
import com.swgk.core.BR;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MDateUtil;
import java.util.List;

/**
 * 个人中心——集采管理——我的监督  列表适配器    实体类可能需要更换
 */
public class JCMySupervisionAdapter extends BaseRecycleAdapter<JcMySupervisionEntity> {

    private DeleteListerner deleteListener;

    public JCMySupervisionAdapter(Context context, List<JcMySupervisionEntity> datas) {
        super(context, R.layout.item_jc_my_supervision, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, JcMySupervisionEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tv_accusation_item = holder.itemView.findViewById(R.id.tv_accusation_item);
        tv_accusation_item.setText(getAccusationItem(entity.getAccusationItem()));
        TextView tv_create_time = holder.itemView.findViewById(R.id.tv_create_time);
        tv_create_time.setText(MDateUtil.getDate(entity.getCreateTime()));
        TextView tv_finish_time = holder.itemView.findViewById(R.id.tv_finish_time);
        TextView tvStatus = holder.itemView.findViewById(R.id.tv_status);
        LinearLayout llDealtime = holder.itemView.findViewById(R.id.ll_dealtime);
        TextView tvName = holder.itemView.findViewById(R.id.tv_name);
        tvName.setText("集采名称：" + entity.getGoodsName());
        if (entity.getStatus() == 0) {//待处理
            tv_finish_time.setText("");
            tvStatus.setText("待处理");
            llDealtime.setVisibility(View.GONE);
        } else {//已处理
            tv_finish_time.setText(MDateUtil.getDate(entity.getFinishTime()));
            tvStatus.setText("已处理");
            llDealtime.setVisibility(View.VISIBLE);
        }
        tvStatus.setOnClickListener(view -> {
            if (null != deleteListener) {
                deleteListener.delete(entity);
            }
        });
    }

    private String getAccusationItem(String item) {
        String name = new String();
//        1，行贿受贿，2，服务态度，3，商业欺诈，4，违约纠纷，5，工作作风，6，工作纠偏，7，其他
        switch (item) {
            case "1":
                name = "行贿受贿";
                break;
            case "2":
                name = "服务态度";
                break;
            case "3":
                name = "商业欺诈";
                break;
            case "4":
                name = "违约纠纷";
                break;
            case "5":
                name = "工作作风";
                break;
            case "6":
                name = "工作纠偏";
                break;
            default:
            case "7":
                name = "其他";
                break;
        }
        return name;
    }


    public interface DeleteListerner {
        void delete(JcMySupervisionEntity entity);

    }

    public void setDeleteListener(DeleteListerner listener) {
        this.deleteListener = listener;
    }
}
